#include <iostream>

using namespace std;

const int N = 100010;
int Size[N], p[N];
int n, m;

int find(int a)
{
    if (p[a] == a)
    {
        return a;
    }
    p[a] = find(p[a]);
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        Size[i] = 1;
        p[i] = i;
    }
    while (m--)
    {
        char op[2];
        int a, b;
        scanf("%s", op);
        if (op[0] == 'C')
        {
            cin >> a >> b;
            a = find(a), b = find(b);
            if (a != b)
            {
                p[a] = b;
                Size[b] += Size[a];
            }
        }
        else if (op[1] == '1')
        {
            cin >> a >> b;
            if (find(a) == find(b))
            {
                puts("Yes");
            }
            else 
            {
                puts("No");
            }
        }
        else
        {
            cin >> a;
            a = find(a);
            printf("%d\n", Size[a]);
        }
    }
    return 0;
}